package org.ki4.kipastelsys.auth

import org.ki4.kipastelsys.enums.Sexo

class Pessoa {

    String nome
    String endereco
    String telefone
    String cpf
    Sexo sexo
    Date dataDeNascimento
    String username
    String password
    Date dateCreated
    boolean enabled = true
    boolean accountExpired
    boolean accountLocked
    boolean passwordExpired

    static constraints = {
        nome blank: false
        endereco blank: false
        telefone blank: false
        cpf blank:false
        dataDeNascimento blank:false
        sexo blank: false
        username blank: false, unique: true
        password (blank: false, password:true)
        enabled display: false
        accountExpired display: false
        passwordExpired display: false
    }

    static mapping = {
        password column: '`password`'
        sort "nome"
        id cascade: "all-delete-orphan"
    }

    String toString(){
        return "${username}"
    }

    Set<Funcao> getAuthorities() {
        PessoaFuncao.findAllByPessoa(this).collect { it.funcao } as Set
    }
}
